<template>
  <div class="app-container">
    <div>
      <el-row class="admin-top-g">
        <!-- 设置了新增的时候才显示加载按钮 -->
        <GButton
          :is-del-show="!!(limits.length >=1 && limits.filter(it => it.FName === '删除').length)"
          :is-plus-show="!!(limits.length >=1 && limits.filter(it => it.FName === '加载').length)"
          :is-add-show="false"
          :is-edit-show="false"
          :lists="options"
          @onAdd="addUser"
          @onEdit="editUser"
          @onDelete="delUser"
          @onPlus="plus"
          @selectSettings="selectSettings"
        />

      </el-row>
      <br>
      <el-row>
        <template v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length">
          <el-date-picker
            v-model="qjValue"
            style="width: 195px;"
            type="month"

            placeholder="选择年度"
            @change="selectPeriod"/>
          <el-input v-model="keyword" clearable style="width: 195px;" placeholder="请输入关键字" @keyup.native.enter="searchUser" @change="searchUser"/>
          <!--  <el-select v-model="fdeleted" filterable clearable style="width: 160px;" placeholder="请选择在职状态" @change="searchUser">
            <el-option
              v-for="item in fdeletedList"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select> -->
          <el-select v-model="fcompany" clearable filterable placeholder="请选择公司" @change="searchUser">
            <el-option
              v-for="item in gsList"
              :key="item.finterid"
              :label="item.fname"
              :value="item.fname"/>
          </el-select>

          <el-select v-model="fdeptname" clearable filterable placeholder="请选择部门" @change="searchUser">
            <el-option
              v-for="item in bmList"
              :key="item.finterid"
              :label="item.fname"
              :value="item.fname"/>
          </el-select>

          <el-select v-model="fstatus" clearable filterable style="width: 160px;" placeholder="请选择审核状态" @change="searchUser">
            <el-option
              v-for="item in statusList"
              :key="item.fstatus"
              :label="item.fname"
              :value="item.fstatus"/>
          </el-select>

          <el-select v-model="ffustatus" clearable filterable style="width: 160px;" placeholder="请选择复审状态" @change="searchUser">
            <el-option
              v-for="item in fustatusList"
              :key="item.ffustatus"
              :label="item.fname"
              :value="item.ffustatus"/>
          </el-select>

          <el-button type="primary" icon="el-icon-search" @click="searchUser">搜索</el-button>
          <!-- <el-button v-if="this.$route.query.qjValue" type="success" icon="el-icon-download" @click="downData">导出</el-button> -->
          <el-button type="success" icon="el-icon-download" @click="downData">导出</el-button>
          <el-button type="success" icon="el-icon-refresh" @click="refresh">刷新</el-button>
          <!-- <el-select v-model="appUser" filterable clearable placeholder="请选择员工" @change="searchUser">
            <el-option
              v-for="item in appUserList"
              :key="item.FUserID"
              :label="item.FName"
              :value="item.FUserID"/>
          </el-select> -->
          <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '审核').length" type="success" icon="el-icon-circle-check" @click="check('1')">审核</el-button>
          <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '反审核').length" type="success" icon="el-icon-close" @click="check('0')">反审核</el-button>
          <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '复审').length" type="success" icon="el-icon-circle-check" @click="fucheck('1')">复审 </el-button>
          <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '反复审').length" type="success" icon="el-icon-close" @click="fucheck('0')">反复审</el-button>
        </template>
      </el-row>
    </div>
    <br>
    <el-table
      v-loading="listLoading"
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      :key="key"
      :data="tableData"
      :summary-method="getSummaries"
      :render-header="labelHead"
      :header-cell-style="tableHeaderStyle"
      max-height="750"
      class="table-1"
      show-summary
      element-loading-text="正在加载"
      border
      fit
      highlight-current-row
      @selection-change="handleSelectionChange"
      @current-change="salaryCurrentChange">
      <el-table-column
        type="selection"
        width="55"/>
      <!-- <el-table-column v-for="item in formThead" :width="item.frepwid" :key="item.frepindex" :label="item.frepcap" align="center"> -->
      <el-table-column v-for="item in formThead" :key="item.fid" :label="item.frepcap" :prop="item.frepfld" :width="item.frepwid" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <template v-if="item.frepfld === 'fstatus'">
            <el-tag v-if="Number(scope.row[item.frepfld]) === 1" type="success">已审</el-tag>
            <el-tag v-else type="danger">未审</el-tag>
          </template>
          <template v-else-if="item.frepfld === 'ffustatus'">
            <el-tag v-if="Number(scope.row[item.frepfld]) === 1" type="success">已复审</el-tag>
            <el-tag v-else type="danger">未复审</el-tag>
          </template>
          <template v-else-if="item.frepfld === 'fhiredate'">
            {{ scope.row[item.frepfld] ? scope.row[item.frepfld].split('-').join(''): '' }}
          </template>
          <template v-else-if="item.frepfld === 'fdeleted'">
            <el-tag v-if="Number(scope.row[item.frepfld]) === 0" type="success">在职</el-tag>
            <el-tag v-if="Number(scope.row[item.frepfld]) === 1" type="danger">自离</el-tag>
            <el-tag v-if="Number(scope.row[item.frepfld]) === 2" type="danger">辞职未发放</el-tag>
            <el-tag v-if="Number(scope.row[item.frepfld]) === 3" type="danger">请长假</el-tag>
            <el-tag v-if="Number(scope.row[item.frepfld]) === 4" type="danger">辞职已发放</el-tag>
            <el-tag v-if="Number(scope.row[item.frepfld]) === 5" type="danger">已补发</el-tag>
            <el-tag v-if="Number(scope.row[item.frepfld]) === 6" type="danger">待辞职</el-tag>
          </template>
          <template v-else>
            {{ scope.row[item.frepfld] }}
          </template>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      :total="total"
      :page-sizes="pagesizes"
      :page-size="pagesize"
      :current-page.sync="currentPage"
      class="jy-pagination"
      style="text-align: center; margin-top: 20px;"
      background
      layout="sizes, prev, pager, next, total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"/>

    <el-dialog v-el-drag-dialog :visible.sync="addUserModal" title="添加／编辑">
      <el-form v-loading="loadingForm" ref="form" :rules="rules" :model="form" label-width="140px">
        <el-form-item v-for="item in dialogThead" :key="item.frepindex" :label="item.frepcap" :prop="item.frepfld">
          <!-- 年份 -->
          <template v-if="item.frepfld === 'FYear'">
            <el-date-picker
              v-model="form[item.frepfld]"
              style="width: 100%;"
              type="year"
              value-format="yyyy"
              placeholder="选择年度"/>
          </template>
          <!-- 下拉框 -->
          <template v-else-if="item.frepmeg == 1">
            <template v-if="item.frepfld === 'FPeriod'">
              <el-select v-model="form[item.frepfld]" clearable filterable placeholder="请选择" style="width: 100%;">
                <el-option
                  v-for="item in periodList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </template>
            <template v-else>
              <el-select v-model="form[item.frepfld]" clearable filterable placeholder="请选择" style="width: 100%;">
                <el-option
                  v-for="item in nickNameList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </template>
          </template>
          <!-- 输入框 -->
          <template v-else>
            <el-input v-model="form[item.frepfld]" />
          </template>

        </el-form-item>

        <el-form-item>
          <el-button :loading="loadingForm" type="primary" @click="confirm" >确认</el-button>
          <el-button @click="addUserModal=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 参数配置 -->
    <el-dialog v-el-drag-dialog :visible.sync="configModal" :close-on-click-modal="false" class="config-dialog">
      <head-table
        :config-list="configList"
        :key-value="key"
        @updateConfigData="getUpdateConfigData" />
    </el-dialog>

    <!-- SQL弹窗 -->
    <el-dialog v-el-drag-dialog :visible.sync="dialogSQLModal" :append-to-body="true" title="执行结果">
      <el-form v-loading="loadingFormSQL" ref="formSQL" :rules="rulesSQL" :model="formSQL" label-width="120px">
        <el-form-item label="SQL语句" prop="gzsql">
          <el-input v-model="formSQL.gzsql" :autosize="{ minRows: 14 }" type="textarea"/>
        </el-form-item>
        <el-form-item>
          <el-button :loading="loadingFormSQL" type="primary" @click="confirmSQL" >确认</el-button>
          <el-button @click="dialogSQLModal=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>
<script>
let FRepKey = ''
const defaultFormThead = []
const date = new Date().getDate()
const t = new Date(new Date().getTime() - date * 24 * 60 * 60 * 1000)
const defaultOptions = [
  {
    value: 0,
    label: '单据设置'
  },
  {
    value: 1,
    label: '显示SQL语句'
  }
]
import { download } from '../../mixins/download.js'
import { common } from '../../mixins/common'
import { company } from '../../mixins/company'
import { bumen } from '../../mixins/bumen'
import { pagination } from '../../mixins/pagination'
import { configColumn, erpZhiyuan, checkStatus, AppUser } from '../../api/salary'
import { genAdd, genDel, genList } from '../../api/gen'
import HeadTable from './headTable/index.vue'
import { tableConfig, apiSql, apiFileSave } from '../../api/account'
import { periodList, getYearMonth } from '../../utils/index'
export default {
  name: 'Index',
  components: {
    HeadTable
  },
  mixins: [download, common, company, bumen, pagination],
  data() {
    return {
      // 弹窗下拉列表
      // postLists: [],
      nickNameList: [], // 职员姓名
      periodList: [],

      value: '',
      options: [],
      FRepKey: '',
      qjValue: this.$route.query.qjValue ? this.$route.query.qjValue : getYearMonth(t),
      keyword: '',
      fdeleted: '',
      fdeletedList: [
        {
          value: 0,
          label: '全部'
        },
        {
          value: 1,
          label: '在职'
        },
        {
          value: 2,
          label: '自离'
        },
        {
          value: 3,
          label: '辞职未发放'
        },
        {
          value: 4,
          label: '请长假'
        },
        {
          value: 5,
          label: '辞职已发放'
        },
        {
          value: 6,
          label: '已补发'
        },
        {
          value: 7,
          label: '待辞职'
        }
      ],
      // 表头、表格设置
      tableData: [],
      tableList: [],
      defaultFormThead: [],
      formThead: defaultFormThead,
      dialogThead: [],
      curData: {},

      listLoading: false,
      list: [],

      addUserModal: false,
      loadingForm: false,
      isEditor: false,
      form: {},
      rules: {
        FYear: [
          { required: true, message: '请选择年度', trigger: 'change' }
        ],
        FPeriod: [
          { required: true, message: '请选择期间', trigger: 'change' }
        ],
        FName: [
          { required: true, message: '请选择职员姓名', trigger: 'change' }
        ]
      },
      // 参数配置
      configModal: false,
      configLoading: false,
      configList: [],
      key: 0,

      // SQL弹窗
      dialogSQLModal: false,
      loadingFormSQL: false,
      formSQL: {
        gzsql: ''
      },
      rulesSQL: {

      },

      // 审核数据
      checkData: [],
      selectedData: [],
      appUserList: [],
      appUser: '',
      appname: '',

      // 用户菜单
      menusList: [],
      limits: [],
      userKey: ''

    }
  },
  async mounted() {
    this.userKey = this.$route.meta.FRepKey

    FRepKey = this.$route.meta.FRepKey
    this.options = defaultOptions
    this.periodList = periodList
    // this.getErpZhiyuan()
    // await this.getBodyData()
    // await this.getHeadData()
    await this.getAppUser()
    await this.getAllData()
    // if (this.$route.query.qjValue) {
    //   await this.getExportData()
    // }
  },
  methods: {
    // 获取所有表格数据
    // async getExportData() {
    //   if (!this.total) return
    async getExportData(total) {
      if (!total) return
      try {
        const res = await genList({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          FRepKey,
          keyword: this.keyword,
          qjValue: this.qjValue,
          fdeleted: this.fdeleted ? this.fdeleted : '0',
          // limit: this.total,
          limit: total,
          page: this.currentPage
        })

        this.listData = res.Data
        this.formThead.map(item => {
          this.listData.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
      } catch (error) {
        console.log(error)
      }
    },
    // 导出数据
    async downData() {
      this.exportData()
    },
    async getAllData() {
      await this.getBodyData()
      await this.getHeadData()

      // 菜单列表（权限）
      const menuRes = JSON.parse(localStorage.getItem('setMenuData'))
      this.menusList = menuRes
      if (menuRes.length >= 1) {
        menuRes.map(it => {
          it.children.map(item => {
            if (item.fobjectid === this.userKey) {
              this.$set(this, 'limits', item.child)
            }
          })
        })
      }
    },
    // 表格数据
    async getErpZhiyuan() {
      try {
        this.listLoading = true
        const res = await erpZhiyuan({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          limit: 10000
        })
        this.listLoading = false
        res.result.map(item => {
          this.nickNameList.push({
            value: item.FItemID,
            label: item.FName + '(' + item.FNumber + ')'
          })
        })
      } catch (error) {
        this.listLoading = false
        console.log(error)
      }
    },
    selectSettings(val) {
      if (val === 0) {
        this.settings()
      } else if (val === 1) {
        this.dialogSQL()
      }
    },
    salaryCurrentChange(val) {
      this.curData = val
    },
    async getTableConfig() {
      try {
        this.configLoading = true
        const res = await tableConfig({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          key: FRepKey
        })
        this.configList = res.Data
        this.key = FRepKey
        this.configLoading = false
      } catch (error) {
        this.configLoading = false
        console.log(error)
      }
    },
    settings() {
      this.configModal = true
      this.getTableConfig()
    },
    // 更新数据
    async getUpdateConfigData() {
      await this.getTableConfig()
      await this.getBodyData()
      await this.getHeadData()
    },
    // 表头数据
    async getHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.tableData = this.tableList.slice()

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.tableList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
            if (it === 'FHireDate') {
              this.$set(this.listData[index], it, item[it].split('-').join(''))
            }
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'FItemID') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
        console.log(error)
      }
    },
    // 表体数据
    async getBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          FRepKey,
          keyword: this.keyword,
          fdeleted: this.fdeleted ? this.fdeleted : '0',
          fcompany: this.fcompany,
          fdeptname: this.fdeptname,
          fstatus: this.fstatus,
          ffustatus: this.ffustatus,
          qjValue: this.qjValue,
          limit: this.pagesize,
          page: this.currentPage
        })
        this.listLoading = false
        this.tableList = res.Data
        this.total = res.total
        await this.getExportData(this.total)
      } catch (error) {
        this.listLoading = false
        console.log(error)
      }
    },
    selectPeriod(val) {
      this.qjValue = getYearMonth(val)
      this.searchUser()
    },
    async searchUser() {
      await this.getAllData()
    },
    refresh() {
      location.reload()
    },
    async addUser() {
      this.form = {}
      const arr = getYearMonth().split('-')
      const FYear = arr[0]
      const FPeriod = arr[1] > 10 ? arr[1] : Number(arr[1])
      const data = {}
      this.dialogThead.map(item => { data[item.frepfld] = '' })
      for (const i in data) {
        this.$set(this.form, i, data[i])
      }
      delete this.form.FItemID
      this.form.FRepKey = FRepKey
      this.form.FYear = FYear
      this.form.FPeriod = FPeriod

      setTimeout(() => {
        this.$refs['form'].clearValidate()
      })

      this.addUserModal = true
    },
    async confirm() {
      this.$refs['form'].validate(async(valid) => {
        if (valid) {
          this.loadingForm = true
          try {
            this.form.db = this.globalDb.db
            this.form.opername = decodeURIComponent(this.globalDb.fname)
            const res = await genAdd(this.form)
            if (res.Error === 0) {
              this.loadingForm = false
              this.addUserModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })
              await this.getAllData()
            } else {
              this.loadingForm = false
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            this.loadingForm = false
            console.log(error)
          }
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    async editUser() {
      this.form = {}
      if (this.selectedData.length !== 1) {
        this.$message({
          message: '请选中要编辑的一行',
          type: 'warning'
        })
        return
      }

      // const data = this.curData
      const data = this.selectedData[0]
      if (data && Number(data.FStatus) === 1) {
        this.$message({
          message: '已审核，不能修改！',
          type: 'warning'
        })
        return
      }
      // this.dialogThead.map(item => { this.form[item.frepfld] = '' })
      this.dialogThead.map(item => { this.$set(this.form, item.frepfld, '') })
      this.form.fid = ''

      this.addUserModal = true
      for (const i in this.form) {
        this.form[i] = data[i]
      }
      console.log('this.form edit1：', this.form)
      this.form.FRepKey = FRepKey
      this.form.FYear = String(this.form.FYear)
      setTimeout(() => {
        this.$refs['form'].clearValidate()
      })
    },
    async delUser() {
      // const data = this.curData
      const data = this.selectedData
      const isFstatus = data.filter(it => Number(it.fstatus) === 1)
      const fid = data.map(it => it.fid).join(',')
      if (isFstatus.length) {
        this.$message({
          message: '已审核，不能删除！',
          type: 'warning'
        })
        return
      }
      if (!this.checkData.length) {
        this.$message({
          message: '请选中要删除的行',
          type: 'warning'
        })
        return
      }

      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'btn-custom-cancel',
        type: 'warning'
      }).then(async() => {
        const res = await genDel({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          fid,
          FRepKey
        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })

          await this.getAllData()
          return
        }
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 加载工资
    plus() {
      this.$router.push('/salary/caculateWage')
    },
    async handleSizeChange(val) {
      this.currentPage = 1
      this.pagesize = val
      await this.getAllData()
    },
    async handleCurrentChange(val) {
      this.currentPage = val
      await this.getAllData()
    },
    // SQL修改/更新
    async dialogSQL() {
      this.dialogSQLModal = true
      try {
        const res = await apiSql({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          FRepKey
        })

        if (res.Error === 0) {
          this.formSQL.gzsql = res.Data
          this.formSQL.FRepKey = FRepKey
        }
        setTimeout(() => {
          this.$refs['formSQL'].clearValidate()
        })
      } catch (error) {
        console.log(error)
      }
    },
    confirmSQL() {
      this.$refs['formSQL'].validate(async(valid) => {
        if (valid) {
          try {
            this.formSQL.db = this.globalDb.db
            this.formSQL.opername = decodeURIComponent(this.globalDb.fname)
            const res = await apiFileSave(this.formSQL)
            if (res.Error === 0) {
              this.dialogSQLModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })
            } else {
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    labelHead(h, { column, index }) {
      const l = column.label.length
      const f = 16
      column.minWidth = f * l

      return h('div', { class: 'table-head', style: { width: '100%' }}, [column.label])
    },

    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        const values = data.map(item => Number(item[column.property]))
        if (column.property === 'fyfhj' || column.property === 'fsfhj') {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return ((prev + curr) * 100) / 100
            } else {
              return (prev * 100) / 100
            }
          }, 0)
          sums[index] = sums[index].toFixed(2)
        }
      })
      return sums
    },

    handleSelectionChange(val) {
      this.checkData = []
      this.selectedData = val
      val.map(it => {
        this.checkData.push(it.fid)
      })
      console.log(this.checkData.join(','), "  this.checkData.join(', ')")
      // this.checkData = val
    },
    async getAppUser() {
      try {
        const res = await AppUser({
          opername: decodeURIComponent(this.globalDb.fname),
          db: this.globalDb.db
        })
        this.appUserList = res.Data
      } catch (error) {
        console.log(error)
      }
    },
    async check(Fstatus) {
      // if (!this.appUser) {
      //   this.$message({
      //     message: '请选择员工',
      //     type: 'error'
      //   })
      //   return
      // }
      if (!this.checkData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }

      // 判断是否已经复审核了
      for (let i = 0; i < this.selectedData.length; i++) {
        if (this.selectedData[i].ffustatus > 0) {
          this.$message({
            message: this.selectedData[i].fname + '： 已复审不能操作审核',
            type: 'error'
          })
          return
        }
      }
      if (Number(Fstatus) === 1) {
        this.$confirm('是否审核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          cancelButtonClass: 'btn-custom-cancel',
          type: 'warning'
        }).then(async() => {
          try {
            const res = await checkStatus({
              db: this.globalDb.db,
              opername: decodeURIComponent(this.globalDb.fname),
              loginname: decodeURIComponent(this.globalDb.fname),
              FRepKey,
              Fstatus, // 1—审核，0—反审
              fid: this.checkData.join(','),
              appname: ''
            })
            if (res.Error === 0) {
              this.$message({
                message: res.Message,
                type: 'success'
              })
              await this.getAllData()
            } else {
              this.loadingForm = false
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      } else {
        try {
          const res = await checkStatus({
            db: this.globalDb.db,
            opername: decodeURIComponent(this.globalDb.fname),
            loginname: decodeURIComponent(this.globalDb.fname),
            FRepKey,
            Fstatus, // 1—审核，0—反审
            fid: this.checkData.join(','),
            appname: ''
          })
          if (res.Error === 0) {
            this.$message({
              message: res.Message,
              type: 'success'
            })
            await this.getAllData()
          } else {
            this.loadingForm = false
            this.$message({
              message: res.Message,
              type: 'error'
            })
          }
        } catch (error) {
          console.log(error)
        }
      }
    },

    // 复审
    async fucheck(Fstatus) {
      if (!this.checkData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }
      console.log(this.checkData, this.selectedData, 999999999999)
      // 判断是否已经审核了
      for (let i = 0; i < this.selectedData.length; i++) {
        if (this.selectedData[i].fstatus <= 0) {
          this.$message({
            message: this.selectedData[i].fname + ' ：未审核不能做复审',
            type: 'error'
          })
          return
        }
      }

      if (Number(Fstatus) === 1) {
        this.$confirm('是否复审, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          cancelButtonClass: 'btn-custom-cancel',
          type: 'warning'
        }).then(async() => {
          try {
            const res = await checkStatus({
              db: this.globalDb.db,
              opername: decodeURIComponent(this.globalDb.fname),
              loginname: decodeURIComponent(this.globalDb.fname),
              FRepKey,
              Fstatus, // 1—复审核，0—反复审
              fid: this.checkData.join(','),
              appname: '',
              fs: 1
            })
            if (res.Error === 0) {
              this.$message({
                message: res.Message,
                type: 'success'
              })
              await this.getAllData()
            } else {
              this.loadingForm = false
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      } else {
        try {
          const res = await checkStatus({
            db: this.globalDb.db,
            opername: decodeURIComponent(this.globalDb.fname),
            loginname: decodeURIComponent(this.globalDb.fname),
            FRepKey,
            Fstatus, // 1—复审核，0—复反审
            fid: this.checkData.join(','),
            appname: '',
            fs: 1
          })
          if (res.Error === 0) {
            this.$message({
              message: res.Message,
              type: 'success'
            })
            await this.getAllData()
          } else {
            this.loadingForm = false
            this.$message({
              message: res.Message,
              type: 'error'
            })
          }
        } catch (error) {
          console.log(error)
        }
      }
    }

  }
}
</script>
<style lang="scss" scoped>
.config-dialog ::v-deep .el-dialog {
  width: 90%;
}
 .table-head{
    font-size:14px!important;//设置固定的字体大小
  }

 .el-table .cell, .el-table th div{
    padding:0!important;
  }
  .el-table tr td .cell{
    padding:5px 2px !important;
  }
  .el-table .cell, .el-table th div, .el-table--border td:first-child .cell, .el-table--border th:first-child .cell{
    padding-left:0 !important;
  }
</style>

